//
//  SXTTabBarViewController.m
//  SXT
//
//  Created by 赵金鹏 on 16/8/9.
//  Copyright © 2016年 赵金鹏. All rights reserved.
//

#import "SXTTabBarViewController.h"
#import "SXTNavgationController.h"

@interface SXTTabBarViewController ()
/**
 用来存储从plist文件中获取的数据
 */
@property (strong, nonatomic) NSArray *tabBarMessageArray;

@end

@implementation SXTTabBarViewController


- (NSArray *)tabBarMessageArray{
    if (!_tabBarMessageArray) {
        _tabBarMessageArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SXTTabBarViewController" ofType:@"plist"]];
    }
    return _tabBarMessageArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //通过appearance统一设置所有UITabBarItem的文字属性
    //方法或者属性后面带有UI_APPEARANCE_SELECTOR的，都可以通过appearance对象来统一设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],
                                  NSForegroundColorAttributeName:[UIColor grayColor]} forState:(UIControlStateNormal)];
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],
                                                         NSForegroundColorAttributeName:[UIColor colorWithRed:57.0/255.0 green:167.0/255.0 blue:241.0/255.0 alpha:1]} forState:(UIControlStateSelected)];
    
    //添加子控制器
    for (NSDictionary *dic in self.tabBarMessageArray) {
        Class viewControllerClass = NSClassFromString(dic[@"tabbarController"]);
        UIViewController *viewController = [[viewControllerClass alloc]init];
        viewController.tabBarItem.image = [UIImage imageNamed:dic[@"tabbarImage"]];
        viewController.tabBarItem.selectedImage = [UIImage imageNamed:dic[@"tabbarSelectImage"]];
        viewController.title = dic[@"tabbarTitle"];
        SXTNavgationController *navgation = [[SXTNavgationController alloc]initWithRootViewController:viewController];
        [self addChildViewController:navgation];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
